home *** CD-ROM | disk | FTP | other *** search
- #include "SystemSoft.h"
- /*
- File: FormatThisProperty.c
-
- Contains: Store the Name Registry value into the Twist-Down list.
-
- Written by: Martin Minow
-
- Copyright © 1993-95 Apple Computer Inc. All rights reserved.
-
- Change History (most recent first):
-
- 4/3/96 Dave Tarabar SystemSoft Corp
- - no need to display full hex of a driver, limit hex dumps to 10 lines
- - reformat into the style that I like
- */
-
- #include <stdio.h>
- #include "DisplayNameRegistry.h"
- #include <ctype.h>
- #include <string.h>
-
- // To test for a driver (executable code), look at the first 7 bytes of the property.
-
- #define kDriverProperty "driver,"
- #define kAddressProperty "assigned-addresses"
- #define kRegPropery "reg"
- #define IsDriverProperty(property) \
- (strncmp((property), kDriverProperty, 7) == 0)
- #define IsAddressProperty(property) (strcmp((property), kAddressProperty) == 0)
- #define IsRegProperty(property) (strcmp((property), kRegPropery) == 0)
-
- // The PhysAddressProperty structure from IEEE 1275 is used for "reg" and
- // "assigned-address" properties.
-
- typedef struct PhysAddressProperty {
- UInt32 physHi;
- UInt32 physMid;
- UInt32 physLo;
- UInt32 sizeHi;
- UInt32 sizeLo;
- } PhysAddressProperty, *PhysAddressPropertyPtr;
-
- // These masks and values decode the physHi word. The format is
- // npt000ss bbbbbbbb dddddfff rrrrrrrr
- //
- // n 1 = Relocatable, 0 = Absolute
- // p 1 = Prefetchable
- // t 1 = Alias
- // ss Space code (Config, I/O, Mem, 64-bit Mem) 2 bits
- // bbbbbbbb Bus number 8 bits
- // ddddd Device number 5 bits
- // fff Function number 3 bits
- // rrrrrrrr Register number 8 bits
-
- #define kPhysAbsolute 0x80000000 // 0 if relocatable, 1 if not
- #define kPhysPrefetch 0x40000000 // 1 if "prefetchable", 0 if not
- #define kPhysAlias 0x20000000 // 1 if alised (for I/O) or below 1MB (Mem)
- #define kPhysSpaceMask 0x03000000 // Config, Mem, I/O, or 64-bit Mem
- #define kPhysSpaceShift 24
- #define kPhysBusNumberMask 0x00FF0000
- #define kPhysBusNumberShift 16
- #define kPhysDeviceMask 0x0000F800
- #define kPhysDeviceShift 11
- #define kPhysFunctionMask 0x00000700
- #define kPhysFunctionShift 8
- #define kPhysRegisterMask 0x000000FF
- #define kPhysRegisterShift 0
-
-
- //--------------------------------------------------------------------------------
- Boolean FormatStringProperty(RegPropertyValueSize propertySize,
- const void *propertyValue, char *result);
- Boolean FormatStringProperty(RegPropertyValueSize propertySize,
- const void *propertyValue, char *result)
- {
- Boolean isStringProperty, isAscii;
- int i;
- register char *cp;
-
- isStringProperty = FALSE;
- if (propertySize < (kOneLineFormatLength - 3))
- {
- isAscii = TRUE;
- cp = ((char *) propertyValue);
- for (i = 0; isAscii && i < (propertySize - 1); i++)
- isAscii = IS_ASCII_PRINT(cp[i]);
- if (isAscii && cp[i] == '\0')
- {
- sprintf(result, "\"%s\"", cp);
- isStringProperty = TRUE;
- }
- }
- return (isStringProperty);
- }
-
- //--------------------------------------------------------------------------------
- Boolean FormatSmallProperty( RegPropertyValueSize propertySize,
- const void *propertyValue, char *result);
- Boolean FormatSmallProperty( RegPropertyValueSize propertySize,
- const void *propertyValue, char *result)
- {
- Boolean isSmallProperty;
- long *lp;
- short *sp;
-
- isSmallProperty = FALSE;
- if (propertySize == sizeof (short))
- {
- sp = (short *) propertyValue;
- sprintf(result, "[%04x = %d]", ((int) *sp) & 0xFFFF, (int) *sp);
- isSmallProperty = TRUE;
- }
- if (propertySize == sizeof (long))
- {
- lp = (long *) propertyValue;
- sprintf(result, "[%08x = %ld]",
- lp[0], lp[0]
- );
- isSmallProperty = TRUE;
- }
- else if (propertySize == (sizeof (long) * 2))
- {
- lp = (long *) propertyValue;
- sprintf(result, "[%08x = %ld], [%08x = %ld]",
- lp[0], lp[0], lp[1], lp[1]);
- isSmallProperty = TRUE;
- }
- return (isSmallProperty);
- }
-
- //--------------------------------------------------------------------------------
- // FormatOneLineProperty tries to format the property value into a single line.
- // It returns TRUE if it succeeds.
- Boolean FormatOneLineProperty( RegPropertyValueSize propertySize,
- const void *propertyValue, char *result);
- Boolean FormatOneLineProperty( RegPropertyValueSize propertySize,
- const void *propertyValue, char *result)
- {
- Boolean oneLiner;
-
- oneLiner = FormatStringProperty(propertySize, propertyValue, result);
-
- if (oneLiner == FALSE)
- oneLiner = FormatSmallProperty(propertySize, propertyValue, result);
-
- return (oneLiner);
- }
-
- //--------------------------------------------------------------------------------
- // FormatPhysAddressProperty formats a vector of "reg" and/or "assigned-address"
- // descriptor values, as described in IEEE 1275-1994. The caller has checked that this is,
- // indeed, a "reg" or "assigned-address" property. The "reg" property is the primary
- // mechanism that PCI uses to describe a device's physical memory requirements. The
- // "assigned-address" property binds physical addresses to the actual hardware
- // configuration.
- void FormatPhysAddressProperty(PhysAddressPropertyPtr physAddressPropertyPtr,
- short nPhysAddress, TwistDownSiblingSet *twistDownSiblingSetPtr);
- void FormatPhysAddressProperty(PhysAddressPropertyPtr physAddressPropertyPtr,
- short nPhysAddress, TwistDownSiblingSet *twistDownSiblingSetPtr)
- {
- short i;
- unsigned int busNumber, deviceNumber, functionNumber, registerNumber;
- OSErr status;
- char *addressType, *isPrefetch, *isAlias, *isAbsolute;
- char work[256];
- UInt32 cellHi;
-
- for (status = noErr, i = 0; status == noErr && i < nPhysAddress; i++)
- {
- cellHi = physAddressPropertyPtr[i].physHi;
- busNumber = (cellHi & kPhysBusNumberMask) >> kPhysBusNumberShift;
- deviceNumber = (cellHi & kPhysDeviceMask) >> kPhysDeviceShift;
- functionNumber = (cellHi & kPhysFunctionMask) >> kPhysFunctionShift;
- registerNumber = (cellHi & kPhysRegisterMask) >> kPhysRegisterShift;
- isAbsolute = ((cellHi & kPhysAbsolute) != 0) ? "abs" : "rel";
- isPrefetch = ((cellHi & kPhysPrefetch) != 0) ? ", prefetch" : "";
- isAlias = ((cellHi & kPhysAlias) != 0) ? ", alias" : "";
-
- switch ((cellHi & kPhysSpaceMask) >> kPhysSpaceShift)
- {
- case 0: addressType = "Config"; break;
- case 1: addressType = "I/O"; break;
- case 2: addressType = "Mem"; break;
- case 3: addressType = "64-bit"; break;
- }
-
- sprintf(
- work,
- "bus %u, dev %u, func %u, reg %u (%s) %s%s%s, %08lx %08lx %08lx",
- busNumber,
- deviceNumber,
- functionNumber,
- registerNumber,
- addressType,
- isAbsolute,
- isPrefetch,
- isAlias,
- physAddressPropertyPtr[i].physHi,
- physAddressPropertyPtr[i].physLo,
- physAddressPropertyPtr[i].sizeLo
- );
-
- status = MakeTwistDownSibling(twistDownSiblingSetPtr, kValueIndentLevel, strlen(work), (Ptr) work);
- }
- }
-
-
- //--------------------------------------------------------------------------------
- #ifdef SYSF
- // don't print out long hex dumps
- #endif
- TwistDownHdl FormatLargeProperty(const RegPropertyNameBuf foundProperty,
- RegPropertyValueSize propertySize, const void *propertyValue);
- TwistDownHdl FormatLargeProperty(const RegPropertyNameBuf foundProperty,
- RegPropertyValueSize propertySize, const void *propertyValue)
- {
- TwistDownSiblingSet twistDownSiblingSet;
- OSErr status;
- short i,offset,nBytesToDraw;
- unsigned char c;
- unsigned char *cp;
- char work[256], thisValue[80];
- #define kBytesPerLine 16
- #ifdef SYSF
- RegPropertyValueSize savePropertySize = propertySize;
- #endif
-
- NewTwistDownSiblingSet(&twistDownSiblingSet);
- if (IsAddressProperty(foundProperty) || IsRegProperty(foundProperty))
- FormatPhysAddressProperty((PhysAddressPropertyPtr) propertyValue,
- propertySize / sizeof (PhysAddressProperty), &twistDownSiblingSet);
-
- #ifdef SYSF
- if (propertySize > (kMaxLinesToPrint * kBytesPerLine))
- propertySize = (kMaxLinesToPrint * kBytesPerLine);
- #endif
- // Even if it's a known property ("assigned-address"), format the raw hex data.
- cp = (unsigned char *) propertyValue;
- for (offset = 0; offset < propertySize; offset += kBytesPerLine)
- {
- if ((offset + kBytesPerLine) <= propertySize)
- nBytesToDraw = kBytesPerLine;
- else
- nBytesToDraw = propertySize - offset;
-
- sprintf(work, "%04lx:", offset);
- for (i = 0; i < nBytesToDraw; i++)
- {
- sprintf(thisValue, " %02x", cp[offset + i] & 0xFF);
- strcat(work, thisValue);
- }
- for (; i < kBytesPerLine; i++)
- strcat(work, " ");
- strcat(work, " ");
- for (i = 0; i < nBytesToDraw; i++)
- {
- c = cp[offset + i];
- if (c < ' ' || c > '~')
- c = '.';
- thisValue[0] = c;
- thisValue[1] = 0;
- strcat(work, thisValue);
- }
- status = MakeTwistDownSibling(&twistDownSiblingSet, kValueIndentLevel, strlen(work), (Ptr) work);
- }
- #ifdef SYSF
- propertySize = savePropertySize;
- #endif
- return (twistDownSiblingSet.firstElement);
- }
-
-
- //--------------------------------------------------------------------------------
- // OneLineProperty is called by the display list creator to format
- // "property : value" or "path : value" where the entire text fits
- // on a single display line.
- Boolean OneLineProperty( const char *labelText, const TwistDownHdl valueElement, char *oneLineWork)
- {
- int length;
- Boolean oneLiner;
- #define VAL (**valueElement)
-
- if (valueElement == NULL || VAL.nextElement != NULL)
- oneLiner = FALSE;
- else {
- length = strlen(labelText) + strlen(" = ") + VAL.dataLength;
- if (length > kOneLineFormatLength)
- oneLiner = FALSE;
- else {
- oneLiner = TRUE;
- sprintf(
- oneLineWork,
- "%s = %.*s",
- (char *) labelText,
- (int) VAL.dataLength,
- (char *) VAL.data
- );
- }
- }
- return (oneLiner);
- }
-
- //--------------------------------------------------------------------------------
- // Called for all property values.
- TwistDownHdl FormatThisProperty( const RegPropertyNameBuf foundProperty,
- RegPropertyValueSize propertySize, const void *propertyValue)
- {
- TwistDownHdl propertyHdl;
- Boolean oneLiner;
- char work[kOneLineFormatLength + 1];
-
- oneLiner = FormatOneLineProperty(propertySize, propertyValue, work);
-
- if (oneLiner)
- (void) MakeTwistDownElement(NULL, kValueIndentLevel, strlen(work), (Ptr) work, &propertyHdl);
- else
- propertyHdl = FormatLargeProperty(foundProperty, propertySize, propertyValue);
-
- return (propertyHdl);
- }
-